package com.renwu.edu.info.manager.service;

import com.renwu.edu.info.manager.dao.StudentDao;
import com.renwu.edu.info.manager.domain.Student;

public class StudentService {
    private StudentDao studentDao = new StudentDao();
    public boolean AddStudent(Student stu) {
        return studentDao.AddStudent(stu);
    }

    public boolean isExists(int id) {
       Student[] stus = studentDao.findAllStudent();
       boolean exists = false;
        for (int i = 0; i < stus.length; i++) {
            if(stus[i] != null && stus[i].getId() == id){
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Student[] findAllStudent() {
        boolean flag = false;
        for (int i = 0; i < studentDao.findAllStudent().length; i++) {
            if(studentDao.findAllStudent()[i] != null){
                flag = true;
                break;
            }
        }
        if(flag){
            return studentDao.findAllStudent();
        }else{
            return null;
        }
    }

    public void deleteStudent(int deleteId) {
        studentDao.deleteStudent(deleteId);
    }


    public void setStudent(int setId, Student newStu) {
        studentDao.setStudent(setId,newStu);
    }
}
